package com.library.service.impl;


import com.library.common.core.text.Convert;
import com.library.domain.BoBorrow;
import com.library.mapper.BoBorrowMapper;
import com.library.service.IBoBorrowService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


/**
 * 图书借阅 服务层实现
 *
 * @author wanghongjie
 * @date 2020-01-18
 */
@Service
public class BoBorrowServiceImpl implements IBoBorrowService {
    @Autowired
    private BoBorrowMapper boBorrowMapper;

    @Override
    public BoBorrow selectBoBorrowByBookIdAndStatus(Long bookId) {
        return boBorrowMapper.selectBoBorrowByBookIdAndStatus(bookId);
    }

    @Override
    public int deleteUserByIds(String ids) {
        return boBorrowMapper.deleteBoBorrowByIds(ids.split(","));
    }

    /**
     * 查询图书借阅信息
     *
     * @param id 图书借阅ID
     * @return 图书借阅信息
     */
    @Override
    public BoBorrow selectBoBorrowById(Long id) {
        return boBorrowMapper.selectBoBorrowById(id);
    }

    @Override
    public BoBorrow selectBoBorrowByMembersIdAndBookId(BoBorrow boBorrow) {
        return boBorrowMapper.selectBoBorrowByMembersIdAndBookId(boBorrow);
    }

    @Override
    public boolean selectBorrowByMembersId(Long id) {
        List<BoBorrow> boBorrowList = boBorrowMapper.selectBorrowByMembersId(id);
        if (boBorrowList.size() == 0) {
            return true;
        }
        return false;
    }

    @Override
    public List<BoBorrow> selectBorrowListByMembersId(BoBorrow boBorrow) {
        return boBorrowMapper.selectBorrowByMembersId(boBorrow.getMembersId());
    }


    /**
     * 查询图书借阅列表
     *
     * @param boBorrow 图书借阅信息
     * @return 图书借阅集合
     */
    @Override
    public List<BoBorrow> selectBoBorrowList(BoBorrow boBorrow) {
        return boBorrowMapper.selectBoBorrowList(boBorrow);
    }

    /**
     * 新增图书借阅
     *
     * @param boBorrow 图书借阅信息
     * @return 结果
     */
    @Override
    public int insertBoBorrow(BoBorrow boBorrow) {
        return boBorrowMapper.insertBoBorrow(boBorrow);
    }

    /**
     * 修改图书借阅
     *
     * @param boBorrow 图书借阅信息
     * @return 结果
     */
    @Override
    public int updateBoBorrow(BoBorrow boBorrow) {
        return boBorrowMapper.updateBoBorrow(boBorrow);
    }

    /**
     * 删除图书借阅对象
     *
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteBoBorrowByIds(String ids) {
        return boBorrowMapper.deleteBoBorrowByIds(Convert.toStrArray(ids));
    }

}
